package com.common.base.widget.countdownView;

import android.content.Context;

/**
 * Created by sosou on 2017/10/5.
 */
public class CountdownUtils {

    public static int dp2px(Context context, float dpValue) {
        if (dpValue <= 0) return 0;
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    public static float sp2px(Context context, float spValue) {
        if (spValue <= 0) return 0;
        final float scale = context.getResources().getDisplayMetrics().scaledDensity;
        return spValue * scale;
    }

    public static String formatNum(int time,boolean notFillZero) {
        //是否开头补0
        if (notFillZero){
            return String.valueOf(time);
        }else {
            return time < 10 ? "0" + time : String.valueOf(time);
        }
    }

    public static String formatMillisecond(int millisecond) {
        String retMillisecondStr;

//        if (millisecond > 99) {
//            retMillisecondStr = String.valueOf(millisecond / 10);
//        } else if (millisecond <= 9) {
//            retMillisecondStr = "0" + millisecond;
//        } else {
//            retMillisecondStr = String.valueOf(millisecond);
//        } String.valueOf(millisecond);


        if (millisecond > 9) {
//            retMillisecondStr = String.valueOf(millisecond / 10);
            retMillisecondStr = String.valueOf(millisecond / 100);
        } else if (millisecond <= 9) {
            retMillisecondStr =  String.valueOf(millisecond);
        } else {
            retMillisecondStr = String.valueOf(millisecond);
        }

        return retMillisecondStr;
    }

}
